package com.fzy.springsecurity.controller;

import com.fzy.springsecurity.bean.TUser;
import com.fzy.springsecurity.service.TUserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fzy
 * @since 2024-10-04
 */
@RestController
@RequestMapping("tuser")
public class TUserController {
    @Resource
    TUserService tUserService;

    @PostMapping("signin")
    public String signin(@RequestBody TUser tUser) {
        tUserService.saveUserDetails(tUser);
        return "signin";
    }

    @RequestMapping("hello")
    public String hello(HttpServletRequest request) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println("principal: " + authentication.getPrincipal());
        System.out.println("credentials: " + authentication.getCredentials());
        return "hello";
    }
}
